// 发布订阅模式

const fs = require('fs');
const event = {
    _events: [],
    on(fn) {
        this._events.push(fn)
    },
    emit(data) {
        this._events.forEach(fn => fn(data))
    }
}

event.on(() => {
    console.log('每读取一次 就触发一次')
})
const arr = [];
event.on((data) => {
    arr.push(data)
})
event.on((data) => {
    if (arr.length === 2) {
        console.log('读取完毕', arr)
    }
})

fs.readFile('./a.txt','utf8',(err,data)=>{
    event.emit(data)
})
fs.readFile('./a.txt','utf8',(err,data)=>{
    event.emit(data)
})